﻿'''
383赎金信
给你两个字符串：ransomNote 和 magazine ，判断 ransomNote 能不能由 magazine 里面的字符构成。
如果可以，返回 true ；否则返回 false 。
magazine 中的每个字符只能在 ransomNote 中使用一次。
示例 1：
输入：ransomNote = "a", magazine = "b"
输出：false
示例 2：
输入：ransomNote = "aa", magazine = "ab"
输出：false
示例 3：
输入：ransomNote = "aa", magazine = "aab"
输出：true
提示：
1 <= ransomNote.length, magazine.length <= 105
ransomNote 和 magazine 由小写英文字母组成
'''
class Solution(object):
    def canConstruct(self,ransomNote:str,magazine:str)->bool:
        dict_ransom = {}
        for c in ransomNote:
            if c in dict_ransom:
                dict_ransom[c] += 1
            else:
                dict_ransom[c] = 1
        for c in magazine:
            if c in dict_ransom:
                dict_ransom[c] -= 1
        for value in dict_ransom.values():
            if value > 0:
                return False
        return True
#示例
if __name__ == '__main__':
    ransomNote = "a"
    magazine = "b"
    ransomNote1 = "aa"
    magazine1 = "ab"
    ransomNote2 = "aa"
    magazine2 = "aab"
    print(Solution().canConstruct(ransomNote,magazine))
    print(Solution().canConstruct(ransomNote1,magazine1))
    print(Solution().canConstruct(ransomNote2,magazine2))



